
#if defined(WIN32) || defined(WIN64)
#pragma unmanaged
#endif

#ifdef WIN32
#include <windows.h>
#endif

#include <Liberty3D/Engine/Conversion.h>

using namespace Liberty::Engine;

#ifdef WIN32
std::basic_string<wchar_t> Liberty::Engine::UTF8_To_UTF16(const char* s) {
    std::basic_string<WCHAR> w;
    int                      l = MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0);

    w.resize(l - 1);

    MultiByteToWideChar(CP_UTF8, 0, s, -1, (LPWSTR)w.data(), l - 1);
    return w;
}

std::basic_string<wchar_t> Liberty::Engine::UTF8_To_UTF16(const std::string& s) {
    return UTF8_To_UTF16(s.c_str());
}

std::string Liberty::Engine::UTF16_To_UTF8(const wchar_t* s) {
    std::basic_string<char> w;
    int                     l = WideCharToMultiByte(CP_UTF8, 0, s, -1, NULL, 0, NULL, NULL);

    w.resize(l - 1);

    WideCharToMultiByte(CP_UTF8, 0, s, -1, (LPSTR)w.data(), l - 1, NULL, NULL);
    return w;
}

std::string Liberty::Engine::UTF16_To_UTF8(const std::basic_string<wchar_t>& s) {
    return UTF16_To_UTF8(s.c_str());
}

#endif
